﻿toggle = function (fsid)
{
    var div = $id("div_" + fsid);
    //var divImage = $id("divImage_" + fsid);
    //var btn = $id("btn_" + fsid);
    //var btnEdit = $id("btnEdit_" + fsid);
    //var load = $id("load_" + fsid);
        
    var display = "";
    
    if( div.style.display != "none" )
    {
        display = "none";
    }
    
    div.style.display = display;
    //divImage.style.display = display;
    //btn.style.display = display;
    //btnEdit.style.display = display;
    //load.style.display = display;
}
dgCAR_c_CallbackComplete = function(e)
{
    
}
cbkCAR_c_CallbackComplete = function(e) 
{
    var lovhOldCar = $id("lovh_CAR.OLDID");
    var lovhCAR = $id("lovh_CAR.ID"); 
    var lovOldCar = $id("lov_CAR.OLDID");
    var lovCAR = $id("lov_CAR.ID");
    lovOldCar.value = "";
    lovCAR.value = "";
    lovhCAR.value = "";
    lovhOldCar.value = "";
    alert("CAR has been changed");
    var btn = $id("btnChange");
    var load = $id("load");
    btn.style.display = "block";
    load.innerHTML = "";
    dgCAR_c.PerformCallback("CHANGE");
}
SelectCAR = function()
{
    var lovhOldCAR = $id("lovh_CAR.OLDID");
    dgCAR_c.PerformCallback("SELECT" + DELIMITER + lovhOldCAR.value);
}
Change = function()
{
    var btn = $id("btnChange");
    var load = $id("load");
    if(confirm("save changes?"))
    {
        // di sini kirim data perubahannya
        var input = GetData();
        if(input)
        {
            btn.style.display = "none";
            load.innerHTML = "<img src='" + LOADING.src + "' alt='' />"; 
            cbkCAR_c.PerformCallback(input);
        }
        else
        {
            btn.style.display = "block";
            load.innerHTML = "";
        }
    }
}
GetData = function()
{
    var output = "CHANGE" + DELIMITER;
    var iEmptyValueCount = 0;
    var lovhOldCAR = $id("lovh_CAR.OLDID");
    var lovhCAR = $id("lovh_CAR.ID");
    if(lovhCAR.value == "")
    {
        iEmptyValueCount++;
    }
    if(lovhOldCAR.value == "")
    {
        iEmptyValueCount++;
    }
    output += lovhOldCAR.value + DELIMITER + lovhCAR.value;
    var sxError = "";
    if( iEmptyValueCount > 0 )
    {
        sxError += "terdapat field isian yang belum diisi!";
    }
    
    if( sxError != "" )
    {
        alert(sxError);
        return false;
    }
    return output;
}
